﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataPreparation
{
    [Serializable]
    public class GradedDB
    {
        
        public Dictionary<string,IItem> items { get; set; }
        public Dictionary<string, double> CosSim { get; set; }


        public GradedDB()
        {
            items = new Dictionary<string, IItem>();
            CosSim = new Dictionary<string, double>();
        }

        //returns the cosine similarity between two items
        public double GetSimilarity(IItem item1, IItem item2)
        {
            ItemPair p = new ItemPair(item1, item2);
            return CosSim[p.Key()];
        }

    }


    [Serializable]
    public class ItemPair
    {
        private string itemPairKey;

        private IItem item1;
        private IItem item2;


        public IItem Item1
        {
            get { return item1; }
            set { item1 = value; }
        }


        public IItem Item2
        {
            get { return item2; }
            set { item2 = value; }
        }

        public ItemPair(IItem i, IItem j)
        {
            if (string.Compare(i.GetID(), j.GetID()) < 0)
            {
                item1 = i;
                item2 = j;
            }
            else
            {
                item1 = j;
                item2 = i;
            }

            itemPairKey = item1.getName() + item2.getName();
        }

        public string Key()
        {
            return itemPairKey;
        }
    }
}
